package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.InvestpinglunAuthorPhotoDa;
import com.zzk.lanouhn.myapplication1.modles.InvestPingLunAuthorPhotoModle;

/**
 * Created by lanouhn on 16/9/19.
 */
public class InvestPingLunAuthorPhotoAdapter extends RecyclerView.Adapter<InvestPingLunAuthorPhotoAdapter.PhotoHorld> {

    private Context context;
    private InvestPingLunAuthorPhotoModle photoModle;

    public InvestPingLunAuthorPhotoAdapter(Context context, InvestPingLunAuthorPhotoModle photoModle) {
        this.context = context;
        this.photoModle = photoModle;
    }

    @Override
    public PhotoHorld onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_pinglun_author_photo, null);
        PhotoHorld horld = new PhotoHorld(view);
        return horld;
    }

    @Override
    public void onBindViewHolder(PhotoHorld holder, int position) {
        if (photoModle.getData() == null) {

        } else {
            Picasso.with(context).load(photoModle.getData().get(position).getPic_url_small()).into(holder.iv);
            //跳转到大图
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, InvestpinglunAuthorPhotoDa.class);
                    context.startActivity(intent);
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return photoModle.getData().size();
    }

    public class PhotoHorld extends RecyclerView.ViewHolder {
        private ImageView iv;

        public PhotoHorld(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.item_pinglun_photo_iv);
        }
    }

}
